package com.hongkzh.www.look.enterprise.userinfo.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hongkzh.www.R;
import com.hongkzh.www.look.enterprise.userinfo.model.bean.MediaVideoBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 媒体简介 视频 adapter
 */
public class MediaVideoAdapter extends RecyclerView.Adapter<MediaVideoAdapter.ViewHolder> {


    private List<MediaVideoBean.DataBean.ListBean> mVideoList = new ArrayList();
    private MediaVideoBean.DataBean dataVideo;

    private int page;


    public MediaVideoAdapter(int page) {
        this.page = page;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_video, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        holder.tvVideoName.setText(mVideoList.get(position).getTitle());
        holder.tvVideoSubTitle.setText(mVideoList.get(position).getNote());
        Glide.with(holder.itemView).load(mVideoList.get(position).getCoverImgSrc()).into(holder.IvVideo);
    }

    public void add(MediaVideoBean videoBean) {

        if (videoBean != null && !TextUtils.isEmpty(videoBean.getData().getPageNumber() + "")) {
            if (page == videoBean.getData().getPageNumber()) {
                mVideoList = videoBean.getData().getList();
            } else {
                for (int i = 0; i < videoBean.getData().getList().size(); i++) {
                    mVideoList.add(videoBean.getData().getList().get(i));
                }
            }
        }
    }

    public void clearVideoList() {
        if (mVideoList != null && mVideoList.size() != 0) {
            mVideoList.clear();
        }
    }


    @Override
    public int getItemCount() {
        return mVideoList == null ? 0 : mVideoList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.Iv_Video)
        ImageView IvVideo;
        @BindView(R.id.tv_VideoName)
        TextView tvVideoName;
        @BindView(R.id.tv_video_subTitle)
        TextView tvVideoSubTitle;
        @BindView(R.id.tv_playNum)
        TextView tvPlayNum;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
